#!/usr/bin/python
#-*- coding:utf-8 -*-
import ConfigParser, os, platform

class Config(object):
	def __init__(self, cfg_path=os.path.join(os.path.expanduser("~"), ".wxsoft", "wxedit", "wxedit.ini")):
		self.cfg_path = cfg_path
		self.cfg = ConfigParser.ConfigParser()
		if self.cfg.read(cfg_path) != [cfg_path]:
			self.cfg.add_section("Options")
			self.cfg.add_section("View")
			self.cfg.add_section("Window")
		if platform.system() == "Linux":
			self.cfg.set("Options", "EndOfLineMode", "LF")
		elif platform.system() == "Windows":
			self.cfg.set("Options", "EndOfLineMode", "CR + LF")
		else:
			self.cg.set("Options", "EndOfLineMode", "CR")
	def config_write(self, obj, cfg_path=os.path.join(os.path.expanduser("~"), ".wxsoft", "wxedit", "wxedit.ini")):
		a, b = obj.GetPositionTuple()
		self.cfg.set("Window", "Position", repr(a)+","+repr(b))
		if obj.IsMaximized():
			self.cfg.set("Window", "Maximized", True)
		else:
			self.cfg.set("Window", "Maximized", False)
		if obj.IsFullScreen():
			self.cfg.set("Window", "Size", "600,500")
		else:
			a, b = obj.GetSizeTuple()
			self.cfg.set("Window", "Size", repr(a)+","+repr(b))
		try:
			self.cfg.write(open(cfg_path, "w"))
		except IOError:
			return 0
		else:
			return 1